package com.top.mall.jetpack.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.module.lemlin.http.HttpResponseBody
import com.module.lemlin.http.HttpResponseData
import com.module.lemlin.http.SubscribeViewModel
import com.top.mall.base.BaseViewModel
import com.top.mall.entity.OrderDetailsResponse
import com.top.mall.entity.OrderListResponse
import com.top.mall.entity.OrderSubmitResponse
import com.top.mall.jetpack.ma.OrderManager

class OrderViewModel(application: Application) : BaseViewModel(application) {
    private val mOrderManager = OrderManager()
    val orderIndexLiveData = MutableLiveData<HttpResponseBody<OrderListResponse>>()
    fun orderIndex(type: String? = null) {
        setRxLifeScope(SubscribeViewModel(orderIndexLiveData)) {
            mOrderManager.orderIndex(type)
        }
    }

    val orderDetailsLiveData = MutableLiveData<HttpResponseBody<OrderDetailsResponse>>()
    fun orderDetails(order_id: Int) {
        setRxLifeScope(SubscribeViewModel(orderDetailsLiveData)) {
            mOrderManager.orderDetails(order_id)
        }
    }

    val orderSubmitLiveData = MutableLiveData<HttpResponseBody<OrderSubmitResponse>>()
    fun orderSubmit(
        address_id: Int? = null,
        recipient_id: Int? = null,
        delivery_time: Long? = null,
        user_note: String? = null,
        cartList: Array<Int>,
        invoice_id: Int? = null
    ) {
        setRxLifeScope(SubscribeViewModel(orderSubmitLiveData)) {
            mOrderManager.orderSubmit(address_id, recipient_id, delivery_time, user_note, cartList, invoice_id)
        }
    }

    val orderPaymentLiveData = MutableLiveData<HttpResponseBody<HttpResponseData>>()
    fun orderPayment(order_id: Int) {
        setRxLifeScope(SubscribeViewModel(orderPaymentLiveData)) {
            mOrderManager.orderPayment(order_id)
        }
    }
}